package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.contactuser.pojo.dto.ContactUserDeleteBatchDTO;
import com.xbongbong.pro.contactuser.pojo.vo.ContactUserDeleteBatchVO;
import com.xbongbong.saas.domain.entity.PaymentUserEntity;
import com.xbongbong.saas.model.PaymentUserModel;
import com.xbongbong.saas.service.PaymentUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/4/11 15:00
 * @since v1.0
 */
@Service("paymentUserService")
public class PaymentUserServiceImpl implements PaymentUserService {
    private static final Logger LOG = LoggerFactory.getLogger(PaymentUserServiceImpl.class);
    @Resource
    private PaymentUserModel paymentUserModel;

    @Override
    public ContactUserDeleteBatchVO deleteBatch(ContactUserDeleteBatchDTO contactUserDeleteBatchDTO) throws XbbException {
        return null;
    }

    @Override
    public void dataConsistencyUpdateUser(String corpid, String userId, String userName, String userAvatar) throws XbbException {
        try {
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put("corpid", corpid);
            param.put("userId", userId);
            param.put("del", 0);
            List<PaymentUserEntity> paymentUserEntityList = paymentUserModel.findEntitys(param);
            for (PaymentUserEntity entity : paymentUserEntityList) {
                entity.setUserName(userName);
                entity.setUserAvatar(userAvatar);
                paymentUserModel.update(entity);
            }
        } catch (Exception e) {
            LOG.error("PaymentUserServiceImpl.dataConsistencyUpdateUser 出错，corpid=" + corpid + " userId=" + userId + "  userName=" + userName + "  userAvatar=" + userAvatar, e);
        }
    }
}
